//
//  BaseViewController.h
//  TalkTalk
//
//  Created by ypj on 2019/3/19.
//  Copyright © 2019 bancheng. All rights reserved.
//

#import "BaseViewController.h"
#import <UIKit/UIKit.h>
#import "JSONMgr.h"
#import "NSObject+YYModel.h"
#import "LoginPageViewController.h"
@interface BaseViewController ()

@end

@implementation  BaseViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = White_Color;
    [self shouldAutorotate];
    
    [self updateVersion];
    
    // 获取对应的字典
    [BaseViewController getDicDetailDic];
    
}

-(void)uploadNavigatinBarFrame{
    self.barView.frame = CGRectMake(0, LLStatusBar, ScreenWidth, Height_NavBar);
    self.bgImage.frame = CGRectMake(0, 0, ScreenWidth, Height_NavBar);
    self.customerTitleLabel.frame = CGRectMake(self.navigationController.navigationBar.centerX-100, 30, 200, 30);
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setHidden:YES];
    if (self.navigationController.viewControllers.count > 1) {
        self.tabBarController.tabBar.hidden = YES;
    } else {
        self.tabBarController.tabBar.hidden = NO;
    }
    // 获取常用标签
    [BaseViewController getCompanyLabTags];
}


- (void)layoutCustomNav:(UIView *)view title:(NSString *)title
{
    
    UIButton *backBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    backBtn.frame = CGRectMake(18, KStatuesBarHeight, 40, 40);
    [backBtn setImage:[UIImage imageNamed:@"黑色返回"] forState:(UIControlStateNormal)];
    [backBtn addTarget:self action:@selector(pop) forControlEvents:(UIControlEventTouchUpInside)];
    [view addSubview:backBtn];
    
    UILabel *titleLB = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth / 2 - 100, backBtn.Y, 200, 40)];
    titleLB.text = title;
    titleLB.textColor = ColorWith333333;
    titleLB.textAlignment = NSTextAlignmentCenter;
    titleLB.font = [UIFont boldSystemFontOfSize:17];
    [view addSubview:titleLB];
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, kViewTopHeight-1, ScreenWidth, 1)];
    lineView.backgroundColor = [UIColor colorWithHexString:@"#E7EDF2"];
    [view addSubview:lineView];
    self.lineView = lineView;
}
- (void)layoutCustomNavWithWhiteColor:(UIView *)view title:(NSString *)title
{
    
    UIButton *backBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    backBtn.frame = CGRectMake(18, KStatuesBarHeight, 40, 40);
    [backBtn setImage:[UIImage imageNamed:@"白色返回"] forState:(UIControlStateNormal)];
    [backBtn addTarget:self action:@selector(pop) forControlEvents:(UIControlEventTouchUpInside)];
    [view addSubview:backBtn];
    
    UILabel *titleLB = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth / 2 - 100, backBtn.Y, 200, 40)];
    titleLB.text = title;
    titleLB.textColor = UIColor.whiteColor;
    titleLB.textAlignment = NSTextAlignmentCenter;
    titleLB.font = [UIFont systemFontOfSize:17 weight:UIFontWeightMedium];
    [view addSubview:titleLB];
    
}
-(void)pop{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)setNavLeftBarButtonItemCustom:(UIView *)customView
{
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:customView];
    [self setNavLeftBarButtonItem:barButtonItem];
}

- (UIButton *)leftBarButtonItem
{
    self.leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    CGRect statusRect = [[UIApplication sharedApplication] statusBarFrame];
    _leftButton.frame = CGRectMake(5, statusRect.size.height+5, 35, 35);
    [_leftButton setImage:[UIImage imageNamed:@"back_icon"] forState:UIControlStateNormal];
    
    [_leftButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _leftButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [_leftButton addTarget:self action:@selector(backButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    _leftButton.userInteractionEnabled = YES;
    return _leftButton;
}

-(void)backButtonClick:(UIButton *)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)setNavLeftBarButtonItem:(UIBarButtonItem *)barButtonItem
{
    NSArray *barButtons = nil;
    UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    spacer.width = 0.5;
    barButtons = [NSArray arrayWithObjects:spacer, barButtonItem,nil];
   [self.navigationItem setLeftBarButtonItems:barButtons];
}

// 更新版本
- (void)updateVersion{
    NSString *strurl = [[NSString alloc] initWithFormat:@"http://itunes.apple.com/lookup?id=1595816128"];//替换为自己App的ID
    NSURLSession *session=[NSURLSession sharedSession];
    NSURL *url = [NSURL URLWithString:strurl];
    
    //3.创建可变的请求对象
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
    NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error){
        if (ObjectIsEmpty(data))return;
        //8.解析数据
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
        NSArray * results = dict[@"results"];
        NSDictionary * dic = results.firstObject;
        NSString * lineVersion = dic[@"version"];//版本号
        NSString * releaseNotes = dic[@"releaseNotes"];//更新说明
        NSString * trackViewUrl = dic[@"trackViewUrl"];//链接
        NSLog(@"App store版本号:%@",lineVersion);
        NSLog(@"更新说明:%@",releaseNotes);
        NSLog(@"App下载链接:%@",trackViewUrl);
        
        NSCharacterSet *nonDigitCharacterSet = [[NSCharacterSet decimalDigitCharacterSet] invertedSet];
        //获取字符串中的数字
        NSString *appVersion = app_Version;//本地的app版本
        lineVersion = [[lineVersion componentsSeparatedByCharactersInSet:nonDigitCharacterSet] componentsJoinedByString:@""];//App store的app版本
        appVersion = [[appVersion componentsSeparatedByCharactersInSet:nonDigitCharacterSet ] componentsJoinedByString:@""];
        
        NSLog(@"结果是本地的app版本:%@ \n App store的app版本:%@ ", appVersion, lineVersion);
        
        // 获取NSUserDefaults对象
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:lineVersion forKey:@"App_store_version"];
        [defaults synchronize];  //如果要立刻保存就需要这行代码
        
        if ([lineVersion integerValue] > [appVersion integerValue]) {//App store的app版本>//本地的app版本 时要提醒升级
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"更新");
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"有新版本可用,去更新" preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *update = [UIAlertAction actionWithTitle:@"去更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:trackViewUrl] options:@{} completionHandler:nil];
                }];
                
                [alertController addAction:update];
                [self presentViewController:alertController animated:YES completion:nil];
            });
        }else{
            NSLog(@"没有新版本不用更新提示");
        }
        
    }];
    //7.执行任务
    [dataTask resume];
}


-(int)compareDate:(NSString*)date01 withDate:(NSString*)date02{

     int ci;
    //date01过期时间   date02当前时间
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"yyyy-MM-dd"];
    NSDate *dt1;
    NSDate *dt2;
    dt1 = [df dateFromString:date01];
    dt2 = [df dateFromString:date02];
    NSComparisonResult result = [dt1 compare:dt2];
    switch (result)
    {
        //date02>date01大
        case NSOrderedAscending: ci=1;
        break;
            //date02<date01小
        case NSOrderedDescending: ci=-1;
        break;
            //date02=date01
        case NSOrderedSame: ci=0; break;
        default: NSLog(@"erorr dates %@, %@", dt2, dt1);
        break;
    }
    return ci;
}
//获取字符串的高度
- (CGSize)sizeWithStringAndWidth:(CGFloat)width string:(NSString *)string font:(UIFont *)font
{
    CGRect rect = [string boundingRectWithSize:CGSizeMake(width, 800)//限制最大的宽度和高度
                                       options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesFontLeading  |NSStringDrawingUsesLineFragmentOrigin//采用换行模式
                                    attributes:@{NSFontAttributeName: font}//传人的字体字典
                                       context:nil];
    return rect.size;
}
- (CGFloat)getWidthWithText:(NSString *)text height:(CGFloat)height font:(CGFloat)font{
    
    CGRect rect = [text boundingRectWithSize:CGSizeMake(MAXFLOAT, height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]} context:nil];
    return rect.size.width;
    
}
/**
 push到下一个controller
 */
- (void)pushToNextController:(UIViewController *)controller{
     controller.hidesBottomBarWhenPushed = YES;
    [self.navigationController.navigationBar setHidden:NO];
    [self.navigationController pushViewController:controller animated:YES];
}
- (void)dismiss{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)jumpVC:(UIViewController *)vc{

    NSArray *vcs = self.navigationController.viewControllers;
    NSMutableArray *newVCS = [NSMutableArray array];
    if ([vcs count] > 0){
        for (int i=0; i < [vcs count]-1; i++) {
            [newVCS addObject:[vcs objectAtIndex:i]];
        }
    }
    [newVCS addObject:vc];
    [self.navigationController setViewControllers:newVCS animated:YES];

}
/**
 35  *  删除账号信息
 36  *
 37  *  @return
 38  */
-(BOOL)deleteAccount
{
    return [[NSFileManager defaultManager] removeItemAtPath:YYCAccountPath error:nil];
}
//比较两个数组是否一致
-(BOOL)ArrayIsALickWithOldArray:(NSMutableArray *)oldArray withNewArray:(NSMutableArray *)newArray{
    bool bol = false;
    NSMutableArray *oldArr = [NSMutableArray arrayWithArray:oldArray];
    NSMutableArray *newArr = [NSMutableArray arrayWithArray:newArray];

    [oldArr sortUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
        return obj1 > obj2;
    }];
    
    [newArr sortUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
        return obj1 > obj2;
    }];

    if (newArr.count == oldArr.count) {
        bol = true;

        for (int16_t i = 0; i < oldArr.count; i++) {

            NSString  * c1 =[NSString stringWithFormat:@"%@",[oldArr objectAtIndex:i]] ;
            NSString  *newc= [NSString stringWithFormat:@"%@",[newArr objectAtIndex:i]];

            if (![newc  isEqualToString:c1]) {

                bol = false;
                break;
                
            }
        }
    }
    return bol;
}

- (void)dropShadowWithOffset:(CGSize)offset
                      radius:(CGFloat)radius
                       color:(UIColor *)color
                     opacity:(CGFloat)opacity {
    
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathAddRect(path, NULL, self.navigationController.navigationBar.bounds);
    _barView.layer.shadowPath = path;
    CGPathCloseSubpath(path);
    CGPathRelease(path);
    self.navigationController.navigationBar.layer.shadowColor = color.CGColor;
    self.navigationController.navigationBar.layer.shadowOffset = offset;
    self.navigationController.navigationBar.layer.shadowRadius = radius;
    self.navigationController.navigationBar.layer.shadowOpacity = opacity;
    self.navigationController.navigationBar.clipsToBounds = NO;
    
}

+ (UIWindow *)getCurrentWindow
{
    if ([[[UIApplication sharedApplication] delegate] window]) {
        return [[[UIApplication sharedApplication] delegate] window];
        
    } else {
        if(@available(iOS 13.0, *)) {
            NSArray *array =[[[UIApplication sharedApplication] connectedScenes] allObjects];
            UIWindowScene* windowScene = (UIWindowScene*)array[0];
            UIWindow* mainWindow = [windowScene valueForKeyPath:@"delegate.window"];
            if(mainWindow) {
                return mainWindow;
            } else {
                return [UIApplication sharedApplication].windows.lastObject;
            }
        } else {
            return [UIApplication sharedApplication].keyWindow;
        }
    }
}



-(void)saveUserInfo:(NSDictionary *)cacheDic{
    YLUserInfo *info = [YLUserMgr fetchUser];
    if (info == nil) info = [[YLUserInfo alloc] init];
    info.loginNo    = cacheDic[@"loginNo"];
    info.addBy      = cacheDic[@"addBy"];
    info.addTime    = cacheDic[@"addTime"];
    info.carNum     = cacheDic[@"carNum"];
    info.defaultMan = cacheDic[@"defaultMan"];
    info.delFlag    = cacheDic[@"delFlag"];
    info.editBy     = cacheDic[@"editBy"];
    info.editTime   = cacheDic[@"editTime"];
    info.companyId  = cacheDic[@"companyId"];
    info.enterpriseName = cacheDic[@"enterpriseName"];
    info.id         = cacheDic[@"id"];
    info.imNum      = cacheDic[@"imNum"];
    info.logoUrl    = cacheDic[@"logoUrl"];
    info.nickName   = cacheDic[@"nickName"];
    info.password   = cacheDic[@"password"];
    info.phone      = cacheDic[@"phone"];
    info.telePhone  = cacheDic[@"phone"];
    info.username   = cacheDic[@"username"];
    info.workAddress= cacheDic[@"workAddress"];
    info.roleName   = cacheDic[@"roleName"];
    info.roleId     = cacheDic[@"roleId"];
    info.realName   = cacheDic[@"realName"];
    info.userId     = cacheDic[@"userId"];
    info.workAddressStr = cacheDic[@"workAddressStr"];
    info.avatar     = cacheDic[@"avatar"];   //头像
    [YLUserMgr saveUser:info];
    self.userInfo   = [YLUserMgr fetchUser];
    
}


- (ResponseClass *) convertToResponseClassWithDict:(NSDictionary *) dict{
    if([[dict objectForKey:@"data"] isKindOfClass:[NSArray class]]){
        ResponseClass *rc = [ResponseClass<NSArray *> yy_modelWithDictionary:dict];
//        ResponseClass *rc = [ResponseClass<NSArray *> modelWithDictionary:dict];
        return rc;
    }else{
//        ResponseClass *rc = [ResponseClass<NSDictionary *> modelWithDictionary:dict];
        ResponseClass *rc = [ResponseClass<NSDictionary *> yy_modelWithDictionary:dict];
        return rc;
    }
}




///获取个人信息
- (void)getUserInfo:(getSuccessBlock)block {
    
    NSString *url = [NSString stringWithFormat:@"%@%@",DOMAIN_URL,USER_URL];

    [MSNetworkManager getRevertUrl:url params:@{} success:^(id  _Nonnull paginationObj, id  _Nonnull resonseObj, BOOL isSuccess, NSString * _Nonnull message) {
        
        if(isSuccess){
            NSDictionary *objects = resonseObj[@"sysUser"];
            
            // 用户聊天
            [[MSStorageUtils shareInstance] userDefaultSave:objects[@"imAccount"] withKey:U_Im_Token];
            // 用户真实姓名
            [[MSStorageUtils shareInstance] userDefaultSave:objects[@"realNmae"] withKey:U_Name];
            // 用户头像
            [[MSStorageUtils shareInstance] userDefaultSave:objects[@"avatar"] withKey:U_HImage];
            // 用户手机
            [[MSStorageUtils shareInstance] userDefaultSave:objects[@"phone"] withKey:U_Phone];
            
            
            
            [self saveUserInfo:objects];
            for (NSDictionary *dic in resonseObj[@"roleList"]) {
                if (resonseObj) {
                    NSString *roleName = dic[@"roleName"];
                    NSString *roleId = dic[@"roleId"];
                    NSString *roleCode = dic[@"roleCode"];
                    
                    kUserDefaultSetValue(roleName, COMPANY_ROLE_NAME);
                    kUserDefaultSetValue(roleId, COMPANY_ROLE_ID);
                    kUserDefaultSetValue(roleCode, EduitString_key);

                }
            }
            block(YES);
            return;
        }
        block(NO);
        
    } failure:^(NSUInteger code, NSString * _Nonnull message) {
        block(NO);
    } withShowHud:NO];
    
}


+ (NSString *)gs_jsonStringCompactFormatForDictionary:(NSMutableDictionary *)dicJson {
    if (![dicJson isKindOfClass:[NSMutableDictionary class]] || ![NSJSONSerialization isValidJSONObject:dicJson]) {
        return nil;
    }
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dicJson options:0 error:nil];
    NSString *strJson = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    return strJson;
}

+(id)parseJSONStringToNSDictionary:(NSString *)JSONString {
    NSData *JSONData = [JSONString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *error = nil;
    id jsonObject = [NSJSONSerialization
                     JSONObjectWithData:JSONData options:NSJSONReadingAllowFragments
                     error:&error];
    if (jsonObject != nil && error == nil){
        NSLog(@"反序列化成功...");
        if ([jsonObject isKindOfClass:[NSDictionary class]]){
            NSDictionary *deserializedDictionary = (NSDictionary *)jsonObject;
            NSLog(@"反序列化后的dictionary数据 = %@", deserializedDictionary);
            return deserializedDictionary;
        }else if ([jsonObject isKindOfClass:[NSArray class]]){
            NSArray *deserializedArray = (NSArray *)jsonObject;
            NSLog(@"反序列化json后的数组 = %@", deserializedArray);
            return deserializedArray;
        }else {
            return nil;
        }
    } else {
        NSLog(@"%@", error);
        NSLog(@"反序列化时发生一个错误");
        return nil;
    }
}

///获取当前屏幕显示的viewcontroller
+ (UIViewController *)getCurrentViewController {
    UIViewController *result = nil;
       UIWindow *window = [[UIApplication sharedApplication] keyWindow];
       if (window.windowLevel != UIWindowLevelNormal)
       {
           NSArray *windows = [[UIApplication sharedApplication] windows];
           for(UIWindow * tmpWin in windows)
           {
               if (tmpWin.windowLevel == UIWindowLevelNormal)
               {
                   window = tmpWin;
                   break;
               }
           }
       }
         
       UIView *frontView = [[window subviews] objectAtIndex:0];
       id nextResponder = [frontView nextResponder];
         
       if ([nextResponder isKindOfClass:[UIViewController class]])
           result = nextResponder;
       else
           result = window.rootViewController;
         
       return result;
}

- (BOOL)isValidateMobile:(NSString *)mobile {
    NSString *phoneRegex = @"1[3456789]([0-9]){9}";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", phoneRegex];
    return [phoneTest evaluateWithObject:mobile];
}
   
- (NSURL *)strWithImgUrlString:(NSString *)str
{
    str = [str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    return  [NSURL URLWithString:str];
}


-(void)loginOut{
    [[MSStorageUtils shareInstance] userDefaultSave:@"NO" withKey:USER_DEFAULT_KEY_MEMBER_IsLogin];
    [[SDWebImageDownloader sharedDownloader] cancelAllDownloads];
    [[YTKNetworkAgent sharedAgent] cancelAllRequests];
    [SSKeyChainMgr delLoginToken];
    [YLUserMgr deleteUser];
    LoginPageViewController *pageVC = [[LoginPageViewController  alloc] init];
    UINavigationController *navigationVC = [[UINavigationController alloc] initWithRootViewController:pageVC];
    UIWindow  *mainWindow = [BaseViewController getCurrentWindow];
    [mainWindow setRootViewController:navigationVC];
}
-(void)setBottomViewWithText:(NSString *)text{
    
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(15, kScreenHeight - kComHeight - 5, kScreenWidth - 30, kComHeight)];
    btn.backgroundColor = mainColor;
    btn.layer.cornerRadius = 4;
    btn.layer.masksToBounds = YES;
    [btn setTitle:text forState:UIControlStateNormal];
    [btn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    btn.titleLabel.font = Fond16;
    [[BaseViewController getCurrentVC].view addSubview:btn];
    [btn addTarget:self action:@selector(clickBottomView:) forControlEvents:UIControlEventTouchUpInside];
    
}
-(void)clickBottomView:(UIButton *)sender{
}
//获取当前屏幕显示的viewcontroller
+ (UIViewController *)getCurrentVC
{
 UIWindow *window = [UIApplication sharedApplication].delegate.window;
   NSLog(@"window level: %.0f", window.windowLevel);
   if (window.windowLevel != UIWindowLevelNormal) {
       NSArray *windows = [[UIApplication sharedApplication] windows];
       for (UIWindow * tmpWin in windows) {
           if (tmpWin.windowLevel == UIWindowLevelNormal) {
               window = tmpWin;
               break;
           }
       }
   }
   
   //从根控制器开始查找
   UIViewController *rootVC = window.rootViewController;
   UIViewController *activityVC = nil;
   
   while (true) {
       if ([rootVC isKindOfClass:[UINavigationController class]]) {
           activityVC = [(UINavigationController *)rootVC visibleViewController];
       } else if ([rootVC isKindOfClass:[UITabBarController class]]) {
           activityVC = [(UITabBarController *)rootVC selectedViewController];
       } else if (rootVC.presentedViewController) {
           activityVC = rootVC.presentedViewController;
       }
        else {
           break;
       }
       
       rootVC = activityVC;
   }
    if (activityVC==nil) {
        activityVC = [[UIViewController alloc] init];
    }
   return activityVC;
 
    
}

+(void)getCompanyLabTags{
    
    if (userIsLogin) {
        NSString *url = GET_GetLabTags;
        
        [MSNetworkManager getRevertUrl:url params:@{} success:^(id  _Nonnull paginationObj, id  _Nonnull resonseObj, BOOL isSuccess, NSString * _Nonnull message) {
            
            if (isSuccess) {
                [[NSUserDefaults standardUserDefaults] setValue:StringIsEmpty(resonseObj[@"tags"])?NULL:resonseObj[@"tags"] forKey:k_CYBQ];
            }
            
        } failure:^(NSUInteger code, NSString * _Nonnull message) {
        } withShowHud:NO];
    }
    
   
}
+ (void)getDicDetailDic{
    
    
    /**CLGM   车辆规模,
     XZFW   薪资范围，
     SJSX    司机属性
     GHCS   过户次数
     YXPT   运行平台
     CLLX   车辆类型，
     SYNX   车辆使用年限
     YXXZ   营运性质查询
     ENERGE_TYPE 能源类型
     CLGM   车辆规模
     多个使用逗号间隔*/
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    NSString *json = @"YXPT,CLLX,YXXZ,GHCS,SYNX,CLGM,ENERGE_TYPE";
    
    [params setObject:json forKey:@"code"];
    NSString *url = [NSString stringWithFormat:@"%@?code=%@",CarDetailDict,json];
    [MSNetworkManager postRevertUrl:url params:params success:^(id  _Nonnull paginationObj, id  _Nonnull resonseObj, BOOL isSuccess, NSString * _Nonnull message) {
        if (isSuccess) {
            // 运行品台
            if (!ObjectIsEmpty(resonseObj[@"YXPT"])) {
                [[NSUserDefaults standardUserDefaults] setValue:resonseObj[@"YXPT"] forKey:k_YXPT];
            }
            // 车辆类型
            if (!ObjectIsEmpty(resonseObj[@"CLLX"])) {
                [[NSUserDefaults standardUserDefaults] setValue:resonseObj[@"CLLX"] forKey:k_CLLX];
            }
            // 营运性质
            if (!ObjectIsEmpty(resonseObj[@"YXXZ"])) {
                [[NSUserDefaults standardUserDefaults] setValue:resonseObj[@"YXXZ"] forKey:k_YXXZ];
            }
            // 过户次数
            if (!ObjectIsEmpty(resonseObj[@"GHCS"])) {
                [[NSUserDefaults standardUserDefaults] setValue:resonseObj[@"GHCS"] forKey:k_GHCS];
            }
            // 车牌使用年限
            if (!ObjectIsEmpty(resonseObj[@"SYNX"])) {
                [[NSUserDefaults standardUserDefaults] setValue:resonseObj[@"SYNX"] forKey:k_SYNX];
            }
            // 车辆规模
            if (!ObjectIsEmpty(resonseObj[@"CLGM"])) {
                [[NSUserDefaults standardUserDefaults] setValue:resonseObj[@"CLGM"] forKey:k_CLGM];
            }
            // 能源类型
            if (!ObjectIsEmpty(resonseObj[@"ENERGE_TYPE"])) {
                [[NSUserDefaults standardUserDefaults] setValue:resonseObj[@"ENERGE_TYPE"] forKey:k_NYLX];
            }
            
           
        }

    } failure:^(NSUInteger code, NSString * _Nonnull message) {
    } withShowHud:NO];
    
}
// 获取状态栏高度
+ (CGFloat)getStatusBarHeight
{
    float statusBarHeight = 0;
    if (@available(iOS 13.0, *)) {
        UIStatusBarManager *statusBarManager = [UIApplication sharedApplication].windows.firstObject.windowScene.statusBarManager;
        statusBarHeight = statusBarManager.statusBarFrame.size.height;
    }
    else {
        statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
    }
    return statusBarHeight==0?[UIApplication sharedApplication].statusBarFrame.size.height:statusBarHeight;
}
- (void)backToVC:(NSString *)vc{
    for (UIViewController *controler in self.navigationController.viewControllers) {
        if ([controler isKindOfClass:NSClassFromString(vc)]) {
            [self.navigationController popToViewController:controler animated:YES];
            return;
        }
    }
}
@end
